package controller.v2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import model.AdVO;
import model.BoardVO;
import model.CatVO;
import model.GoodVO;
import model.MemberVO;
import model.SaleVO;
import model.ShowwindowVO;
import service.v2.AdService;
import service.v2.BoardService;
import service.v2.CatService;
import service.v2.ConfigService;
import service.v2.DicService;
import service.v2.GoodService;
import service.v2.MemberService;
import service.v2.MessageService;
import service.v2.SaleService;
import service.v2.ShowwindowService;
import util.NumberUtil;
import util.PackageUtil;
import util.PropertieUtil;
import util.StringUtil;

@RequestMapping("/v2/index")
@Controller
public class IndexController {
	
	@Autowired
	private ConfigService configService;
	@Autowired
	private AdService adService;
	@Autowired
	private BoardService boardService;
	@Autowired
	private CatService catService;
	@Autowired
	private GoodService goodService;
	@Autowired
	private MemberService memberService;
	@Autowired
	private SaleService saleService;
	@Autowired
	private ShowwindowService showwindowService;
	@Autowired
	private MessageService messageService;
	@Autowired
	private DicService dicService;
	
	/**
	 * 系统时间
	 */
	@ResponseBody
	@RequestMapping(value="/getTime",method=RequestMethod.GET)
	public Object getTime(@RequestHeader(value = "LANG", required = false) String lang, HttpServletRequest request, HttpServletResponse response, BoardVO boardVO) throws Exception{
		Map map = new HashMap();
		map.put("time", configService.getTime());
		return PackageUtil.packageParams(200,"success",map,"");
	}
	/**
	 * 热门搜索
	 */
	@ResponseBody
	@RequestMapping(value="/searchList",method=RequestMethod.GET)
	public Object searchList(@RequestHeader(value = "LANG", required = false) String lang, HttpServletRequest request, HttpServletResponse response, BoardVO boardVO) throws Exception{
		String hot_board_cat = "";
		if("en".equals(lang)){
			hot_board_cat = PropertieUtil.loadPropertie("hot_board_cat_en");
		}else{
			hot_board_cat = PropertieUtil.loadPropertie("hot_board_cat");
		}
		boardVO.setCat_id(hot_board_cat);
		List<BoardVO> boardList = boardService.selectBoardAll(boardVO);
		return PackageUtil.packageParams(200,"success",boardList,"");
	}
	/**
	 * cat_id
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="/commonCatList",method=RequestMethod.GET)
	public Object commonCatList(@RequestHeader(value = "LANG", required = false) String lang, HttpServletRequest request, HttpServletResponse response, String cat_id) throws Exception{
		if(cat_id==null || "".equals(cat_id)){
			return PackageUtil.packageParams(10001,"缺少必选参数","","");
		}
		List<CatVO> catList = catService.getIndexActivityCatList(cat_id);
		return PackageUtil.packageParams(200,"success",catList,"");
	}
	
	/**
	 * 登录广告图
	 */
	@ResponseBody
	@RequestMapping(value="/loginAdList",method=RequestMethod.GET)
	public Object loginAdList(@RequestHeader(value = "SECRET", required = false) String member_id, @RequestHeader(value = "OS", required = false) String os, @RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response, AdVO adVO, MemberVO memberVO) throws Exception{
		adVO.setCat_id(PropertieUtil.loadPropertie("cat_login_ad"));
		List<AdVO> adList = adListByCat(member_id, os, screenwidth, adVO);
		return PackageUtil.packageParams(200,"success",adList,"");
	}
	/**
	 * 启动广告图
	 */
	@ResponseBody
	@RequestMapping(value="/startAdList",method=RequestMethod.GET)
	public Object startAdList(@RequestHeader(value = "SECRET", required = false) String member_id, @RequestHeader(value = "OS", required = false) String os, @RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response, AdVO adVO, MemberVO memberVO) throws Exception{
		adVO.setCat_id(PropertieUtil.loadPropertie("cat_start_ad"));
		List<AdVO> adList = adListByCat(member_id, os, screenwidth, adVO);
		return PackageUtil.packageParams(200,"success",adList,"");
	}
	/**
	 * 广告轮播图
	 */
	@ResponseBody
	@RequestMapping(value="/adList",method=RequestMethod.GET)
	public Object adList(@RequestHeader(value = "LANG", required = false) String lang, @RequestHeader(value = "SECRET", required = false) String member_id, @RequestHeader(value = "OS", required = false) String os, @RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response, AdVO adVO, MemberVO memberVO) throws Exception{
		String app_ad = "";
		if("en".equals(lang)){
			app_ad = PropertieUtil.loadPropertie("app_ad_en");
		}else{
			app_ad = PropertieUtil.loadPropertie("app_ad");
		}
		adVO.setCat_id(app_ad);
		List<AdVO> adList = adListByCat(member_id, os, screenwidth, adVO);
		return PackageUtil.packageParams(200,"success",adList,"");
	}

	public List<AdVO> adListByCat(String member_id, String os, String screenwidth, AdVO adVO) throws Exception {
		List<AdVO> adList = adService.selectAdVoAll(adVO, os, member_id, PropertieUtil.loadPropertie("vip_level"));
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			adService.processImg(adList, screenwidth,1);
		}
		return adList;
	}
	
	/**
	 * @param cat_id
	 * @return 广告轮播图通用接口
	 */
	@ResponseBody
	@RequestMapping(value="/adCommonList",method=RequestMethod.GET)
	public Object adCommonList(@RequestHeader(value = "SECRET", required = false) String member_id, @RequestHeader(value = "OS", required = false) String os, @RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response, AdVO adVO, MemberVO memberVO) throws Exception{
		if(adVO.getCat_id()==null || "".equals(adVO.getCat_id())){
			return PackageUtil.packageParams(10001,"缺少必选参数","","");
		}
		List<AdVO> adList = adListByCat(member_id, os, screenwidth, adVO);
		return PackageUtil.packageParams(200,"success",adList,"");
	}
	
	/**
	 * 公告栏
	 */
	@ResponseBody
	@RequestMapping(value="/noticeListAll",method=RequestMethod.GET)
	public Object noticeList(HttpServletRequest request, HttpServletResponse response, BoardVO boardVO) throws Exception{
		boardVO.setCat_id(PropertieUtil.loadPropertie("app_notice"));
		List<BoardVO> boardList = boardService.selectBoardAll(boardVO);
		return PackageUtil.packageParams(200,"success",boardList,""); 
	}
	
	/**
	 * 商品分类
	 */
	@ResponseBody
	@RequestMapping(value = "/catList", method = RequestMethod.GET)
	public Object catList(@RequestHeader(value = "LANG", required = false) String lang,
			@RequestHeader(value = "SECRET", required = false) String member_id,
			@RequestHeader(value = "OS", required = false) String os,
			@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request,
			HttpServletResponse response, CatVO catVO, AdVO adVO, String promotion_id) throws Exception {
		String good_cat = "";
		if("en".equals(lang)){
			good_cat = PropertieUtil.loadPropertie("good_cat_en");
		}else{
			good_cat = PropertieUtil.loadPropertie("good_cat");
		}
		catVO.setParent_id(good_cat);
		List<CatVO> catList = catService.getListAllByParent(catVO);
		// 图片缩放
		if (screenwidth != null && StringUtil.isNumeric(screenwidth)) {
			for (CatVO vo : catList) {
				catService.processImg(vo.getCatList(), screenwidth, 4);
			}
		}
		Map map = new HashMap();
		map.put("catList", catList);
		
		//支持旧版本
//		adVO.setCat_id(PropertieUtil.loadPropertie("app_ad_small"));
//		List<AdVO> adList = adService.selectAdVoAll(adVO, os, member_id, PropertieUtil.loadPropertie("vip_level"));
		//图片缩放
//		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
//			adService.processImg(adList, screenwidth,4);
//		}
//		map.put("adSmallList", adList);
		return PackageUtil.packageParams(200,"success",map,"");
	}
	
	/**
	 * 首页小图
	 */
	@ResponseBody
	@RequestMapping(value="/indexAdList",method=RequestMethod.GET)
	public Object indexAdList(@RequestHeader(value = "LANG", required = false) String lang,
			@RequestHeader(value = "SECRET", required = false) String member_id,
			@RequestHeader(value = "OS", required = false) String os,
			@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request,
			HttpServletResponse response, CatVO catVO, AdVO adVO, MemberVO memberVO, SaleVO saleVO) throws Exception {
		Map map = new HashMap();
		String app_ad_small = "";
		if("en".equals(lang)){
			app_ad_small = PropertieUtil.loadPropertie("app_ad_small_en");
		}else{
			app_ad_small = PropertieUtil.loadPropertie("app_ad_small");
		}
		adVO.setCat_id(app_ad_small);
		List<AdVO> adList = adService.selectAdVoAll(adVO, os, member_id, PropertieUtil.loadPropertie("vip_level"));
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			adService.processImg(adList, screenwidth,4);
		}
		map.put("adSmallList", adList);
		//友米广场小红点
		if(member_id != null){
			int count = adService.getMaterialRead(member_id);
			map.put("material_read", count);
		}
		return PackageUtil.packageParams(200,"success",map,""); 
	}
	
	/**
	 * 首页广告位
	 */
	@ResponseBody
	@RequestMapping(value="/indexSpaceList",method=RequestMethod.GET)
	public Object indexSpaceList(@RequestHeader(value = "SECRET", required = false) String member_id, @RequestHeader(value = "OS", required = false) String os, @RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response
			, CatVO catVO, AdVO adVO, MemberVO memberVO) throws Exception{
		Map map = new HashMap();
		adVO.setCat_id(PropertieUtil.loadPropertie("index_space"));
		List<AdVO> adList = adService.selectAdVoAll(adVO, os, member_id, PropertieUtil.loadPropertie("vip_level"));
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			adService.processImg(adList, screenwidth,2);
		}
		map.put("indexSpaceList", adList);
		return PackageUtil.packageParams(200,"success",map,""); 
	}
	/**
	 * 首页广告位新版
	 */
	@ResponseBody
	@RequestMapping(value="/indexSpaceListNew",method=RequestMethod.GET)
	public Object indexSpaceListNew(@RequestHeader(value = "LANG", required = false) String lang,
			@RequestHeader(value = "SECRET", required = false) String member_id,
			@RequestHeader(value = "OS", required = false) String os,
			@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request,
			HttpServletResponse response, CatVO catVO, AdVO adVO, MemberVO memberVO) throws Exception{
		Map map = new HashMap();
		String index_space_custom = "";
		if("en".equals(lang)){
			index_space_custom = PropertieUtil.loadPropertie("index_space_custom_en");
		}else{
			index_space_custom = PropertieUtil.loadPropertie("index_space_custom");
		}
		adVO.setCat_id(index_space_custom);
		List<AdVO> adList = adService.selectAdVoAll(adVO, os, member_id, PropertieUtil.loadPropertie("vip_level"));
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			adService.processImg(adList, screenwidth,2);
		}
		List<Map<String, List<AdVO>>> l = adService.processRow(adList);
		map.put("indexSpaceList", l);
		return PackageUtil.packageParams(200,"success",map,""); 
	}
	
	/**
	 * 首页活动列表
	 */
	@ResponseBody
	@RequestMapping(value="/indexActivityList",method=RequestMethod.GET)
	public Object indexActivityList(@RequestHeader(value = "LANG", required = false) String lang,
			@RequestHeader(value = "SECRET", required = false) String member_id,
			@RequestHeader(value = "OS", required = false) String os,
			@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request,
			HttpServletResponse response, CatVO catVO, AdVO adVO, MemberVO memberVO) throws Exception {
		Map map = new HashMap();
		List<Map> list = new ArrayList<Map>();
		String index_activity_cat = "";
		if("en".equals(lang)){
			index_activity_cat = PropertieUtil.loadPropertie("index_activity_cat_en");
		}else{
			index_activity_cat = PropertieUtil.loadPropertie("index_activity_cat");
		}
		List<CatVO> indexActivityCatList = catService.getIndexActivityCatList(index_activity_cat);
		for (CatVO vo : indexActivityCatList) {
			GoodVO goodVO = new GoodVO();
			goodVO.setLang(lang);
			goodVO.setCat_id(vo.getCat_id());
			goodVO.setPage_count("8");
			Map goodMap = new GoodController().specialGoodListMap(screenwidth, goodVO, memberVO, goodService, catService);
			list.add(goodMap);
		}
		map.put("indexActivityList", list);
		return PackageUtil.packageParams(200,"success",map,""); 
	}
	
	/**
	 * 热门商品
	 */
	/*@ResponseBody
	@RequestMapping(value="/hotGoodList",method=RequestMethod.GET)
	public Object hotGoodList(@RequestHeader(value = "OS", required = false) String os,@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response, GoodVO goodVO ,@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO) throws Exception{
		goodVO.setCat_id(PropertieUtil.loadPropertie("hot_good"));
		List<GoodVO> list = goodService.getHotList(goodVO);
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			goodService.processImg(list, screenwidth,2);
		}
		if (token != null && member_id != null) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token,os);
			if (memberVO == null) {
				return PackageUtil.packageParams(403, "forbidden", "", "");
			}
		}
		//优惠购
		list = goodService.processGoodList(list, memberVO, "券");
		CatVO catVO = catService.getCatById(PropertieUtil.loadPropertie("hot_good"));
		Map map = new HashMap();
		map.put("goodList", list);
		map.put("cat", catVO);
		return PackageUtil.packageParams(200,"success",map,""); 
	}*/
	
	/**
	 * 人气推荐
	 */
	/*@ResponseBody
	@RequestMapping(value="/popularGoodList",method=RequestMethod.GET)
	public Object popularGoodList(@RequestHeader(value = "OS", required = false) String os,@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response, GoodVO goodVO ,@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO) throws Exception{
		goodVO.setCat_id(PropertieUtil.loadPropertie("popular_good"));
		List<GoodVO> list = goodService.getHotList(goodVO);
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			goodService.processImg(list, screenwidth,2);
		}
		if (token != null && member_id != null) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token,os);
			if (memberVO == null) {
				return PackageUtil.packageParams(403, "forbidden", "", "");
			}
		}
		list = goodService.processGoodList(list, memberVO, "券");
		CatVO catVO = catService.getCatById(PropertieUtil.loadPropertie("popular_good"));
		Map map = new HashMap();
		map.put("goodList", list);
		map.put("cat", catVO);
		return PackageUtil.packageParams(200,"success",map,""); 
	}*/
	
	/**
	 * 特卖活动
	 */
	@ResponseBody
	@RequestMapping(value="/saleIndex",method=RequestMethod.GET)
	public Object saleIndex(@RequestHeader(value = "OS", required = false) String os,@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response, GoodVO goodVO ,@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO,SaleVO saleVO) throws Exception{
		
		saleVO.setFile_cat(PropertieUtil.loadPropertie("good_imgs"));
		List<SaleVO> saleList = saleService.getSaleIndex(saleVO);
		Map map = new HashMap();
		
		String invite_no = "";
		if(member_id !=null && token!=null){
			memberVO = memberService.getMemberByIdCheck(member_id ,token,os);
			if (memberVO == null) {
				return PackageUtil.packageParams(403, "forbidden", "", "");
			}
			invite_no = memberVO.getInvite_no();
		}
		saleList = saleService.setShareMsg(saleList,invite_no);
		map.put("saleList", saleList);
		return PackageUtil.packageParams(200,"success",map,""); 
	}
	
	/**
	 * 随机商品列表
	 */
	@ResponseBody
	@RequestMapping(value="/goodRandomList",method=RequestMethod.GET)
	public Object goodRandomList(@RequestHeader(value = "LANG", required = false) String lang,
			@RequestHeader(value = "OS", required = false) String os,
			@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request,
			HttpServletResponse response, GoodVO goodVO,
			@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO) throws Exception {

		if (token != null && member_id != null) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token,os);
			if (memberVO == null) {
				return PackageUtil.packageParams(403, "forbidden", "", "");
			}
		}
		List<GoodVO> list = null;
		//未登录
//		if(member_id == null){
			goodVO.setPagination(goodVO.getPage_index(), "200");
			goodVO.setLang(lang);
			list = goodService.getRandomGoodListNoLogin(goodVO);
//		}else{
//			//登录
//			String member_recommend = goodService.getMemberRecommend(member_id,goodVO.getPage_count());
//			list = goodService.getRandomGoodListLogin(member_id,member_recommend);
//			if(list.size()==0 || list.size() < Integer.parseInt(goodVO.getPage_count())){
//				if("1".equals(goodVO.getPage_index())){
//					goodVO.setPage_count((Integer.parseInt(goodVO.getPage_count())-list.size())+"");
//					goodVO.setPagination(goodVO.getPage_index(), "200");
//					List<GoodVO> randomList = goodService.getRandomGoodListNoLogin(goodVO);
//					list.addAll(randomList);
//				}else{
//					goodVO.setPagination(goodVO.getPage_index(), "200");
//					list = goodService.getRandomGoodListNoLogin(goodVO);
//				}
//			}
//		}
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			goodService.processImg(list, screenwidth,2);
		}
		list = goodService.processGoodList(list, memberVO, "券");
		Map map = new HashMap();
		map.put("goodList", list);
//		map.put("pagination", goodVO);
		return PackageUtil.packageParams(200,"success",map,"");
	}
	
	/**
	   * 分享接口
	   * @param token  令牌
	   * @param member_id  用户ID
	   * @param type 类型 1邀请 2商品3 优惠活动4 限时购
	   */
	  @ResponseBody
	  @RequestMapping(value = "/shareInfo", method = RequestMethod.GET)
	  public Object shareInfo(@RequestHeader(value = "AUTHORIZATION", required = false) String token,
	      @RequestHeader(value = "SECRET", required = false) String member_id, HttpServletRequest request,
	      HttpServletResponse response, MemberVO memberVO, String type,String promotion_id,String cat_id) {
	    if(type == null || "".equals(type)){
	      return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
	    }
	    Map map = new HashMap();
	    if(member_id != null&&!"".equals(member_id)){
	      if("1".equals(type)){
	        memberVO = memberService.getAllInfoById(member_id);
	        map.put("type", "invite"); 
	        map.put("title", configService.loadConfig("SHARE_TITLE"));
	        map.put("image", configService.loadConfig("APP_LOGO"));
	        map.put("url", configService.loadConfig("WECHAT_HOST")+"/my_inviteRegister?ym_share_inviteno="+memberVO.getInvite_no());
	        map.put("content", configService.loadConfig("SHARE_CONTENT")); 
	      }
	    }
	    if("3".equals(type)){
	      if(promotion_id == null || "".equals(promotion_id)){
	        return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
	      }
	      map.put("title", configService.loadConfig("POROMOTIN_TITLE"));
	      map.put("image", configService.loadConfig("APP_LOGO"));
	      map.put("url", configService.loadConfig("WECHAT_HOST")+"/activity?promotion_id="+promotion_id);
	      map.put("content", configService.loadConfig("PROMOTION_CONTENT")); 
	    }
	    if("4".equals(type)){
	    	map.put("title", configService.loadConfig("LIMITED_SHARE_TITLE"));
	    	map.put("image", configService.loadConfig("APP_LOGO"));
	    	map.put("url", configService.loadConfig("WECHAT_HOST")+"/flashSale");
	    	map.put("content", configService.loadConfig("LIMITED__SHARE_CONTENT")); 
	    }
	    return PackageUtil.packageParams(200,"success",map,"");
	  }
	  
	/*首页橱窗*/
	@ResponseBody
	@RequestMapping(value = "/indexWindowList" , method = RequestMethod.GET)
	public Object indexWindowList(@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth,
			HttpServletRequest request, HttpServletResponse response, 
			@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO, ShowwindowVO showwindowVO) throws Exception {
		showwindowVO.setCat_id(PropertieUtil.loadPropertie("window_community"));
		showwindowVO.setMember_id(member_id);
		List<ShowwindowVO> windowList = 	showwindowService.getIndexList(showwindowVO);
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			showwindowService.processImg(windowList, screenwidth,2);
		}
		CatVO catVO = catService.getCatById(PropertieUtil.loadPropertie("window_community"));
		Map map = new HashMap();
		map.put("cat", catVO);
		map.put("windowList", windowList);
		return PackageUtil.packageParams(200, "successs", map, "");
	}
	
	/*橱窗列表*/
	@ResponseBody
	@RequestMapping(value = "/windowList" , method = RequestMethod.GET)
	public Object windowList(@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth,
			HttpServletRequest request, HttpServletResponse response, GoodVO goodVO,
			@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO, ShowwindowVO showwindowVO) throws Exception {
		showwindowVO.setCat_id(PropertieUtil.loadPropertie("window_community"));
		showwindowVO.setMember_id(member_id);
		int total = showwindowService.getTotal(showwindowVO);
		showwindowVO.setPagination(showwindowVO.getPage_index(), total+"");
		List<ShowwindowVO> windowList = 	showwindowService.getList(showwindowVO);
		 //图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			showwindowService.processImg(windowList, screenwidth,2);
		}
		CatVO catVO = catService.getCatById(PropertieUtil.loadPropertie("window_community"));
		Map map = new HashMap();
		map.put("cat", catVO);
		map.put("windowList", windowList);
		map.put("pagination", showwindowVO);
		return PackageUtil.packageParams(200, "successs", map, "");
	}
	
	/**
	 * 限时购提示
	 * limited_id
	 * tel
	 */
	@ResponseBody
	@RequestMapping(value = "/limitedMsg" , method = RequestMethod.POST)
	public Object limitedMsg(@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth,
			HttpServletRequest request, HttpServletResponse response,
			@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO, String limited_id, String tel) throws Exception {
		if(limited_id==null || "".equals(limited_id) || tel == null || "".equals(tel)){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		if(!NumberUtil.isPhoneNumber(tel)){
			return PackageUtil.packageParams(10000,"参数不正确","",""); 
		}
		int num = 0;
		if(member_id != null){
			num = messageService.checkLimitedMsg(limited_id, member_id);
		}
		if(num > 0){
			messageService.updateLimitedMsg(limited_id, tel, member_id);
		}else{
			messageService.insertLimitedMsg(limited_id, tel, member_id);
		}
		return PackageUtil.packageParams(200, "successs", "", "");
	}
	
	@ResponseBody
	@RequestMapping(value = "/getWord" , method = RequestMethod.GET)
	public Object getWord(@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth,
			HttpServletRequest request, HttpServletResponse response,
			@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO, String word) throws Exception {
		if(word==null || "".equals(word)){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		Map<String, String> result = dicService.getWord(word, PropertieUtil.loadPropertie("word"));
		return PackageUtil.packageParams(200, "successs", result, "");
	}
}
